package com.cyq.order.server;

import com.cyq.order.mapper.OrderMapper;
import com.cyq.order.pojo.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.client.RestTemplate;

import java.util.List;


@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;

    @Transactional
    @Override
    public Order create(Order order) {
        orderMapper.insert(order);

        LinkedMultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<>();
        paramMap.add("productId", order.getProductId());
        String msg = restTemplate.postForObject("http://localhost:8071/stock/reduct", paramMap, String.class);
        log.info("出参：{}", msg);

        int i = 1 / 0;

        return order;
    }

    @Override
    public List<Order> selectAll() {
        return orderMapper.selectAll();
    }
}
